/**
 * @file     titleToNumber.ts
 * @brief    [171. Excel 表列序号](https://leetcode.cn/problems/excel-sheet-column-number/)
 * @author   Zhu
 * @date     2022-10-23 19:07
 */

function titleToNumber(columnTitle: string): number {
    let sum = 0;
    let index = 0;

    do {
        let cur = columnTitle[index];
        sum += getNumber(cur) * 26 ** (columnTitle.length - index - 1);
    } while (++index < columnTitle.length);

    return sum;
}

const A = 'A'.charCodeAt(0);
function getNumber(char: string) {
    return char.charCodeAt(0) - A + 1;
}
